<!-- 用户编辑弹窗 -->
<template>
  <ele-modal
    width="740px"
    :visible="visible"
    :append-to-body="true"
    :close-on-click-modal="false"
    custom-class="ele-dialog-form"
    :title="isUpdate ? '修改优惠券' : '添加优惠券'"
    @update:visible="updateVisible"
  >
    <el-form ref="form" :model="form" :rules="rules" label-width="120px">
     

         <el-form-item label="补贴金额:" prop="subsidy_amount">
        <el-input disabled
          clearable
          v-model="form.subsidy_amount"
          placeholder=""
        />
      </el-form-item>

          <el-form-item label="图片:" prop="subsidy_img">
        <span slot="label">
          图片

          <el-tooltip placement="top">
            <i class="el-icon-question" />
          </el-tooltip>
        </span>
        <el-avatar
          v-if="form.subsidy_img"
          :src="form.subsidy_img"
          shape="square"
          :size="150"
        />
      </el-form-item>
       
  <el-form-item label="审核说明:" prop="subsidy_reason">
        <el-input 
          clearable
          v-model="form.subsidy_reason"
          placeholder=""
        />
      </el-form-item>

      <el-form-item label="消费券类型:" prop="subsidy_status">
        <el-radio-group v-model="form.subsidy_status">
    
                <el-radio :label="4" value="4">通过</el-radio>
          <el-radio :label="3" value="3">驳回</el-radio>
    
        </el-radio-group>
      </el-form-item>


    </el-form>
    <template v-slot:footer>
      <el-button @click="updateVisible(false)">取消 </el-button>
      <el-button type="primary" :loading="loading" @click="save"
        >保存
      </el-button>
    </template>
  </ele-modal>
</template>

<script>
import { add, update } from '@/api/order';
const DEFAULT_FORM = {
  id: 0,
  subsidy_amount: '',
  subsidy_img: '',
  subsidy_status: '',

};

export default {
  name: 'OpenEdit',
  props: {
    // 弹窗是否打开
    visible: Boolean,
    // 修改回显的数据
    data: Object
  },
  data() {
    return {
      // 表单数据

      form: { ...DEFAULT_FORM },
      obj: {},
      // 表单验证规则
      rules: {},
      // 提交状态
      loading: false,
      // 是否是修改
      isUpdate: false,
      num: 1
    };
  },
  methods: {
    updateCount(obj) {
      console.log(obj);
      this.obj = obj;
    },
    handleChange(value) {},
    /* 保存编辑 */
    save() {
      this.$refs['form'].validate((valid) => {
        if (!valid) {
          return false;
        }

        this.loading = true;
        const data = {
          ...this.form
        };

        const saveOrUpdata = this.isUpdate ? update : add;

        saveOrUpdata(data)
          .then((msg) => {
            this.loading = false;
            this.$message.success(msg);
            this.updateVisible(false);
            this.$emit('done');
          })
          .catch((e) => {
            this.loading = false;
            this.$message.error(e.message);
          });
      });
    },
    /* 更新visible */
    updateVisible(value) {
      this.$emit('update:visible', value);
    }
  },
  watch: {
    visible(visible) {
      if (visible) {
        if (this.data) {
          this.$util.assignObject(this.form, {
            ...this.data
          });
          this.isUpdate = true;
        } else {
          this.isUpdate = false;
        }
      } else {
        this.$refs['form'].clearValidate();
        this.form = { ...DEFAULT_FORM };
      }
    }
  }
};
</script>
<style lang="less" scoped>
/deep/ .el-divider--horizontal {
  margin: 0 0 12px 0;
}

.total {
  font-size: 14px;
  font-weight: 400;
  color: #999;
  line-height: 22px;
}
.ivu-text-right {
  text-align: right;
}
.analysis-chart-card-num {
  font-size: 30px;
}

.analysis-chart-card-content {
  height: 40px;
  box-sizing: border-box;
  margin-bottom: 12px;
}

.analysis-chart-card-text {
  padding-top: 12px;
}
.container {
  /* 矩形 6529 */
  padding: 20px;
  height: 61px;
  border-radius: 10px;
  background: rgba(255, 248, 248, 1);
  color: rgba(255, 78, 78, 1);
  font-weight: 700;
  margin-top: 30px;
}
</style>
